<html>
<head><meta charset="utf-8"><title>ambigious code · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html">ambigious code</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246106869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246106869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mahdi Faramarzpour <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246106869">(Jul 15 2021 at 15:01)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/e67cd766f750ddf377ad13552c68465861b09715/crates/ide_assists/src/utils.rs#L310-L317">https://github.com/rust-analyzer/rust-analyzer/blob/e67cd766f750ddf377ad13552c68465861b09715/crates/ide_assists/src/utils.rs#L310-L317</a></p>
<p>what does the doc mean by fn:</p>
<blockquote>
<p>Returns None if we've found an existing fn</p>
</blockquote>



<a name="246107308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246107308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246107308">(Jul 15 2021 at 15:03)</a>:</h4>
<p><code>Option&lt;Option&lt;ast::Impl&gt;&gt;</code>?</p>



<a name="246107584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246107584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246107584">(Jul 15 2021 at 15:05)</a>:</h4>
<p>If I'm reading it right, it returns <code>None</code> if there was an error, <code>Some(None)</code> if it find a block which contains an existing function called <code>name</code> and <code>Some(Some(block))</code> with some arbitrary impl block otherwise.</p>



<a name="246107716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246107716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246107716">(Jul 15 2021 at 15:06)</a>:</h4>
<p>It seems targeted towards adding a new function, as in the "Create method" assist</p>



<a name="246107816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246107816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246107816">(Jul 15 2021 at 15:06)</a>:</h4>
<p>the <code>Option&lt;Option&lt;_&gt;&gt;</code> should probably be replaced by defining a dedicated enum</p>



<a name="246107896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246107896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246107896">(Jul 15 2021 at 15:07)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">S</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>So if you call it with <code>"foo"</code> as <code>name</code>, you get <code>Some(None)</code> and if you call it with <code>"bar"</code> you get <code>Some(Some(..))</code></p>



<a name="246108248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246108248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mahdi Faramarzpour <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246108248">(Jul 15 2021 at 15:10)</a>:</h4>
<div class="codehilite"><pre><span></span><code>if let Some(ref impl_blk) = block {
        if has_fn(impl_blk, name) {
            return None;
        }
    }
</code></pre></div>



<a name="246108348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246108348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mahdi Faramarzpour <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246108348">(Jul 15 2021 at 15:10)</a>:</h4>
<p>Are you sure? looks like it returns None in case of the function existing</p>



<a name="246108415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246108415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246108415">(Jul 15 2021 at 15:11)</a>:</h4>
<p>That's in a <code>find_map</code></p>



<a name="246108436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246108436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246108436">(Jul 15 2021 at 15:11)</a>:</h4>
<p>Ah, no</p>



<a name="246108573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246108573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246108573">(Jul 15 2021 at 15:12)</a>:</h4>
<p>Well, it returns.. something. <code>None</code> if the function exists or there was an error, <code>Some(None)</code> if there's no block and a block otherwise? <span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span></p>



<a name="246109400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/246109400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mahdi Faramarzpour <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#246109400">(Jul 15 2021 at 15:18)</a>:</h4>
<p>yeah, maybe that's the case<br>
thnx</p>



<a name="248476706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/248476706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mahdi Faramarzpour <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#248476706">(Aug 05 2021 at 13:30)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/80f522091a44234bd7ccdbe2ef759252d496227d/crates/ide_assists/src/handlers/generate_function.rs#L229-L232">https://github.com/rust-analyzer/rust-analyzer/blob/80f522091a44234bd7ccdbe2ef759252d496227d/crates/ide_assists/src/handlers/generate_function.rs#L229-L232</a></p>
<p>Can anyone tell me purpose of this struct ?</p>



<a name="248476814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/248476814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#248476814">(Aug 05 2021 at 13:31)</a>:</h4>
<p>I think that's used as the insertion position of the generated function</p>



<a name="248476976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ambigious%20code/near/248476976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ambigious.20code.html#248476976">(Aug 05 2021 at 13:32)</a>:</h4>
<p>Basically whether to put the function after(behind) an item or whether to put it into an ItemList(of a module or block) that is currently empty</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>